package servlets.LoadOnStartup;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Locale;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.PooledConnection;

import myJDBC.myConnection;
import oracle.jdbc.pool.OracleConnectionPoolDataSource;


@WebServlet("/ConnectionPool")
public class ConnectionPool extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	
    public void init( ServletConfig config ) throws ServletException {
		super.init( config );
		if (myConnection.getPool() == null) {
			Locale.setDefault(Locale.ENGLISH);
			try {
				Class.forName("oracle.jdbc.driver.OracleDriver");
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 
		    OracleConnectionPoolDataSource sourse;
		    try {
			    sourse = new OracleConnectionPoolDataSource();
			    sourse.setURL("jdbc:oracle:thin:@localhost:1521:xe");
			    sourse.setUser("NETCRACKER");
			    sourse.setPassword("hammer1945");
			    myConnection.setPool(sourse.getPooledConnection());
		    } catch (SQLException | ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		    }
		}
    }
}
